﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Text;
using System.Windows.Data;

namespace Social_Celebrities
{
   public class AuthorsFromRssText : IValueConverter
    {      
       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {           
           if (value == null)
           {
               return null;
           }
           string author = "";
           if (((System.Collections.ObjectModel.Collection<SyndicationPerson>)value).FirstOrDefault() != null)

               author = ((System.Collections.ObjectModel.Collection<SyndicationPerson>)value).FirstOrDefault().Email;
           else
               return null;

           int maxLength = 15;
           int strLength = 0;
           strLength = author.Length;
           if (strLength == 0)
           {
               return null;
           }
           else if (strLength >= maxLength)
           {
               author = author.Substring(0, maxLength);
               author += "...";
           }
          
           return author;
       }
       public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           throw new NotImplementedException();
       }
    }
 
}
